#include <stdio.h>

int main_28()
{
    int a, score = 0, step = 0;
    while (scanf("%d", &a) != EOF && a)
    {
        if (a == 1)
        {
            score++, step = 0;
        }

        else
        {
            score += ++step * 2;
        }
    }
    printf("%d\n", score);

    return 0;
}
